<template>
  <div class="header">
    <div class="main">
      <a class="toHome" :href="url">
        <!-- <img src="@/assets/img/Wechatlogo.png" alt /> -->
      </a>
      <!-- <div class="username">
        <div v-if="isEpLogin&&isLogin">
          <a :href="url+'/company'" target="_blank">{{ep_userName}}我要招人&nbsp;</a>
          <a :href="url+'/person'" target="_blank">| {{ps_userName}}，欢迎您的登陆!</a>
          <el-button type="text" @click="logout">[退出]</el-button>
        </div>
        <div v-else-if="isLogin">
          <a :href="url+'/person'" target="_blank">{{ps_userName}}，欢迎您的登陆!</a>
          <el-button type="text" @click="logout">[退出]</el-button>
        </div>
        <div v-else-if="isEpLogin">
          <a :href="url+'/company'" target="_blank">{{ep_userName}}，欢迎您的登陆!</a>
          <el-button type="text" @click="logout">[退出]</el-button>
        </div>
        <div v-else class="login">
          <span class="enterprise">
            <a :href="url+'/company/#/register'" target="_blank">免费发布职位</a>
            <a :href="url+'/company/#/login'" target="_blank">企业登录</a>
          </span>
          <span>
            <a :href="url+'/person/#/login'" target="_blank">求职者登录</a>
            <a :href="url+'/person/#/register'" target="_blank">求职者注册</a>
          </span>
        </div>
      </div> -->
    </div>
  </div>
</template>

<script>
import bus from '../common/bus';
import { logOut } from '../../api/login';
export default {
  data () {
    return {
      url: '',
      ps_userName: '',
      ep_userName: ''
    };
  },
  created () {
    // debugger
    this.url = process.env.VUE_APP_URL;
    this.ps_userName = localStorage.getItem('ps_userName') || '';
    this.ep_userName = localStorage.getItem('ep_userName') || '';
    console.log(this.ps_userName, '个人', this.ep_userName);
    console.log(this.isLogin, '个人', this.isEpLogin);

    bus.$on('changeUserName', msg => {
      this.ps_userName = msg;
    });
  },
  props: ['isLogin', 'isEpLogin'],
  methods: {
    logout () {
      logOut().then(data => {
        console.log(data);
        if (data.success) {
          localStorage.setItem('ep_Authorization', '');
          localStorage.setItem('ps_Authorization', '');
          localStorage.setItem('ps_userName', '');
          localStorage.setItem('ps_userId', '');
          localStorage.setItem('ep_userName', '');
          bus.$emit('changeIsLogin', false);
          bus.$emit('changeEpLogin', false);
        } else {
          this.$message.error(`${data.msg}`);
        }
      });
    }
  }
};
</script>

<style lang="css" scoped>
.header {
    width: 100%;
    height: 40px;
    background: rgba(0, 147, 255, 1);
    opacity: 1;
}
.header .main {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 100%;
}
.header a {
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 16px;
    color: rgba(255, 255, 255, 1);
    opacity: 1;
}
a.old_Edition {
    width: 64px;
    margin-left: 70px;
}
.login a {
    margin-right: 10px;
}
.el-button {
    color: rgba(255, 255, 255, 1);
    font-size: 14px;
    font-family: PingFang SC;
    font-weight: 400;
    line-height: 16px;
    opacity: 1;
    margin-left: 10px;
}
.enterprise {
    margin-right: 20px;
}
</style>